<div id="silosLevels" style="height:100%">
        <div class="ui-layout-center">
            <div class="clearfix tbl silosLevelsTable" id="silosLevelsTable"></div>    
        </div>
        <div id="timeFilter_holder" class="clearfix ui-layout-south"></div> 
</div>
<script>
    var silosLevelsFX = function() {
        var _self = this;
        _self.perform = function() {
            //dodavanje layout-a za parent div
            $("#silosLevels").layout({
                resizable: false,
                closable: false,
                south__size: "120"
            });
            $("#timeFilter_holder").load("_parts/TimeFilter.html?x="+Math.random(), function() {
                $('.datepicker.hook_dateFrom').datepicker({
                    defaultDate: '-3m',
                    dateFormat: 'd.m.yy'
                }).datepicker('setDate', '-3m');
                $('.datepicker.hook_dateTo').datepicker({
                    defaultDate: new Date(),
                    dateFormat: 'd.m.yy'
                }).datepicker('setDate', new Date());

                $(".timeFilter #row1 .col5").remove();
                $(".timeFilter #row2 .col5").remove();
                $(".timeFilter #row3 .col5").remove();
                $(".timeFilter #row4 .col4").remove();

                _self.loadYearsForTimeFilter();

                $("#silosLevelsTable").addScroll();
                _self.loadDataForsilosLevels();

                window.refreshAndSortTable = _self.refreshSortedTable;
            });
        };
        _self.refreshSortedTable = function(table, columnName, ascDesc, callback){
            _self.table = table;
            _self.request = 300;

            _self.columnName = columnName;
            _self.sortItem = "";
            _self.ascDesc = ascDesc;
            _self.action = "getItems";

            _self.random = Math.random();
            _self.url = "js/tableParams/" + _self.request + ".json?x=" + random;

            $.get(_self.url, function(response) {
                $(response.desc).each(function(index,value){
                    if(value.title == columnName){
                        _self.sortItem = value.param;
                        return false;
                    }
                });

                var params = {
                    request: _self.request,
                    action: _self.action,
                    sortItem: _self.sortItem,
                    ascDesc: _self.ascDesc
                };

                window.tableConstructor.generateTable(params, callback);
            });

        };
        
        _self.loadYearsForTimeFilter = function(callback) {
            $.getJSON(window.CONSTANTS.SERVICE_URL, {
                request: 300,
                action: 'getYears'
            },
            function(response) {
                $.each(response, function(index, value) {
                    $(".timeFilter .hook_yYear").append("<option>" + value.availableYear + "</option>");
                    $(".timeFilter .hook_mYear").append("<option>" + value.availableYear + "</option>");
                });
                if (callback) {
                    callback();
                }
            });
        };
        _self.refresh = function() {
            $("body").css('cursor', 'wait');
            _self.loadDataForsilosLevels(function() {
                $("body").css('cursor', 'default');
            });
        };
        _self.assignEventHandlers = function() {
            $(document).on("click", ".timeFilter button.refresh", function() {
                _self.refresh();
            });
        };
        _self.clearEventHandlers = function() {
            $(document).off("click", ".timeFilter button.refresh");
        };
        _self.loadDataForsilosLevels = function(callback) {
            var params = {
                request: 300,
                action: "getItems"
            };
            window.tableConstructor.generateTable(params, callback);
        };
    };
    new silosLevelsFX();
    if(!window.sLevelsFX){
        window.sLevelsFX = new silosLevelsFX();
        window.sLevelsFX.perform();
        window.sLevelsFX.clearEventHandlers();
        window.sLevelsFX.assignEventHandlers();
    }
    else{
        window.sLevelsFX.perform();
        window.sLevelsFX.clearEventHandlers();
        window.sLevelsFX.assignEventHandlers();
    }
</script>